﻿unit UFrameUniName;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit, dxSkinsCore,
  cxTextEdit, cxLabel, cxGroupBox, dxSkinOffice2007Blue, cxCheckBox,
  Vcl.StdCtrls, dxbar, Menus, cxButtons;

type
  TFrameUniName = class(TFrame)
    Group1: TcxGroupBox;
    lblName: TcxLabel;
    lblUniName: TcxLabel;
    edtUniName: TcxTextEdit;
    edtRegName: TcxTextEdit;
    lblRegName: TcxLabel;
    edtName: TcxTextEdit;
    chkUseName: TCheckBox;
    btnTranslit: TcxButton;
    chkUniq: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure edtNameExit(Sender: TObject);
    procedure edtNameKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edtRegNameKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edtUniNameExit(Sender: TObject);
    procedure edtUniNameKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edtUniNamePropertiesChange(Sender: TObject);
    procedure edtNamePropertiesChange(Sender: TObject);
    procedure edtRegNamePropertiesChange(Sender: TObject);
    procedure btnTranslitClick(Sender: TObject);
    procedure edtNameKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edtUniNameKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    function EnableSave: Boolean;
    procedure SetLang;
    { Public declarations }
  end;

implementation

{$R *.dfm}

uses ULang, UPasswd;

procedure TFrameUniName.btnTranslitClick(Sender: TObject);
begin
  if edtUniName.Text <> '' then
  begin
    edtRegName.Text := edtUniName.Text;
    edtName.Text := edtUniName.Text;
  end
  else
  begin
    if edtName.Text <> '' then
    begin
      edtUniName.Text := edtName.Text;
      edtRegName.Text := edtName.Text;
    end
    else
    begin
      edtName.Text := edtRegName.Text;
      edtUniName.Text := edtRegName.Text;
    end;
  end;
end;

procedure TFrameUniName.Button1Click(Sender: TObject);
begin
  // edtName.Text:=Translit(edtUniName.Text)
end;

procedure TFrameUniName.edtNameExit(Sender: TObject);
begin
  edtRegName.SelectAll;
end;

procedure TFrameUniName.edtNameKeyDown(Sender: TObject; var Key: Word; Shift:
    TShiftState);
begin
 if Key=VK_RETURN then   edtRegName.SetFocus;
end;

procedure TFrameUniName.edtNameKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  EnableSave;
end;

procedure TFrameUniName.edtNamePropertiesChange(Sender: TObject);
begin
  EnableSave;
end;

procedure TFrameUniName.edtRegNameKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  EnableSave;

end;

procedure TFrameUniName.edtRegNamePropertiesChange(Sender: TObject);
begin
  EnableSave;
end;

procedure TFrameUniName.edtUniNameExit(Sender: TObject);
begin
  edtName.SelectAll;
end;

procedure TFrameUniName.edtUniNameKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_RETURN then
  begin
    btnTranslitClick(Sender);
    edtName.SetFocus;
  end;

end;

procedure TFrameUniName.edtUniNameKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  EnableSave;
end;

procedure TFrameUniName.edtUniNamePropertiesChange(Sender: TObject);
begin
  EnableSave;
end;

function TFrameUniName.EnableSave: Boolean;
begin
  if (edtName.Text <> '') and (edtUniName.Text <> '') and (edtRegName.Text <> '')
  then
    Result := True
  else
    Result := False;
  // ShowMessage(BoolToStr(Result));
end;

procedure TFrameUniName.SetLang;
begin
  case FPasswd.edtLang.ItemIndex of
    0:
      begin
        lblUniName.Caption := 'Международный';
        lblName.Caption := 'Русский';
        lblRegName.Caption := 'Региональный';
        btnTranslit.Caption := 'Клон';
        chkUseName.Caption := 'Использовать в названии';
        chkUniq.Caption := 'Уникальное';
      end;
    1:
      begin
        lblUniName.Caption := 'International';
        lblName.Caption := 'Russian';
        lblRegName.Caption := 'Regional';
        btnTranslit.Caption := 'Clone';
        chkUseName.Caption := 'Use the name of the';
        chkUniq.Caption := 'Unique';
      end;
    2:
      begin
        lblUniName.Caption := 'Internacional';
        lblName.Caption := 'Ruso';
        lblRegName.Caption := 'Regional';
        btnTranslit.Caption := 'Clon';
        chkUseName.Caption := 'Usar en el nombre';
        chkUniq.Caption := 'Único';
      end;
  end;
end;

end.
